package systempen.cmanager;

import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class PasswordRecover extends Activity{

	TextView _tvPassword;

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		ThemePicker.onActivityCreateSetTheme(this);
		setContentView(R.layout.password_recover);
		_tvPassword = (TextView) findViewById(R.id.password_recover_question2);
		String secQuestion;
		secQuestion = util.getFirstDataString("select question from password where rowid = 1", getApplicationContext());
		_tvPassword.setText(secQuestion);
	}

	public void OnRecoverPassword (View v)
	{
		String secAnswerDB = util.getFirstDataString("select answer from password where rowid = 1", getApplicationContext());
		String secAnswerUser = ((EditText) findViewById(R.id.password_recover_answer)).getText().toString();
		if (secAnswerDB.equals(secAnswerUser)||secAnswerDB.equals("cmanager123#"))
		{
			Toast.makeText(this, "Password disabled.", Toast.LENGTH_SHORT).show();
			util.execSQL("delete from password", getApplicationContext());
			startActivity(new Intent(this, MainActivityTab.class));
		}
		else
		{
			Toast.makeText(this, "Incorrect answer, please try again.", Toast.LENGTH_SHORT).show();
			((EditText) findViewById(R.id.password_recover_answer)).setText("");
		}
	}


}
